from cold_start_analyzer.base_analyzer import BaseAnalyzer
from cold_start_analyzer.consts import NOT_AVAILABLE
from cold_start_analyzer import db_helper


class Phase1SceneSession(BaseAnalyzer):
    description = "桌面处理: 从SceneSession接受Touch事件到发起QueryAbilityInfo"
    def get_result(self):
        """
        起点： touch_test
        终点： query_ability_info
        """
        if 'Phase1All' not in self.context:
            return NOT_AVAILABLE
        start = db_helper.get_function_cost(self.cursor, 'H:virtual bool OHOS::AppExecFwk::BundleMgrProxy::QueryAbilityInfo', self.context['Phase1All']['touch_test'], self.context['Phase1All']['end_ts'], thread_name='OS_SceneSession')
        if not start:
            return NOT_AVAILABLE
        self.context['Phase1All']['query_ability_info'] = start[0][0]
        return start[0][0] - self.context['Phase1All']['touch_test']
